﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Globalization;

namespace _06.QuadricEquation
{
    class quadricEquation
    {
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Console.WriteLine("Insert coeficients of a quadric equation");
            Console.Write("a= ");
            string first = Console.ReadLine();
            Console.Write("b= ");
            string second = Console.ReadLine();
            Console.Write("c= ");
            string third = Console.ReadLine();
            double a, b, c, x1, x2, d;
            if (double.TryParse(first, out a))
            {
                Console.Write("");
            }
            else 
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("You should write an integer number!!!");
            }
            if (double.TryParse(second, out b))
            {
                Console.Write("");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("You should write an integer number!!!");
            }
            if (double.TryParse(third, out c))
            {
                Console.Write("");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("You should write an integer number!!!");
            }

            //Check if a = 0;

            if (a == 0)
            {
                return;
            }
            else
            {
                d = Math.Sqrt(Math.Pow(b, 2) - (4 * a * c));
                if (d == 0)
                {
                    x1 = (-b + d) / (2 * a);
                    x2 = (-b + d) / (2 * a);
                    Console.WriteLine("x1 = x2 = {0}", x1);
                }
                else if (d < 0)
                {
                    Console.WriteLine("There are no real roots!!!");
                }
                else
                {
                    x1 = (-b + d) / (2 * a);
                    x2 = (-b - d) / (2 * a);
                    Console.WriteLine("x1 = {0}",x1);
                    Console.WriteLine("x2 = {0}",x2);
                }
            }
        }
    }
}
